/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package guzik.lukasz.snpexplorer;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import javax.swing.tree.TreePath;

/**
 *
 * @author Łukasz 'byku' Guzik
 */
class TransferableTreeNode implements Transferable
{
    public static DataFlavor TREE_PATH_FLAVOR =
	    new DataFlavor(TreePath.class, "Tree path");
    DataFlavor[] flavors =
    {
	TREE_PATH_FLAVOR
    };
    TreePath treePath;

    public TransferableTreeNode(TreePath treePath)
    {
	this.treePath = treePath;
    }

    @Override
    public synchronized DataFlavor[] getTransferDataFlavors()
    {
	return flavors;
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor)
    {
	return (flavor.getRepresentationClass() == TreePath.class);
    }

    @Override
    public Object getTransferData(DataFlavor flavor) throws
	    UnsupportedFlavorException, IOException
    {
	if(isDataFlavorSupported(flavor))
	{
	    return treePath;
	} else
	{
	    throw new UnsupportedFlavorException(flavor);
	}
    }
}
